home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4490 / 4490.xpi / components / scripts / pop3.js < prev    next >
Text File  |  2010-01-22  |  2KB  |  84 lines

  1. /**********************************************************
  2. POP3
  3. **********************************************************/
  4. var name="POP3";
  5. var needServer=true;
  6.  
  7. function init(){
  8.   this.initStage=ST_DATA;
  9.   if(!this.server&&this.user.indexOf("@")!=-1)this.server="pop."+this.user.split("@")[1];  
  10. }
  11. function processSocket(aData){
  12.   if(aData.indexOf("+OK")==0){
  13.     if(!this.process(null,aData))++this.stage;
  14.   }else{
  15.     this.onError();
  16.   }
  17. }
  18. function process(aHttpChannel, aData) {
  19.   switch(this.stage){
  20.   case ST_DATA:
  21.     var ar=this.server.split(":");    
  22.     var port=ar[1]?ar[1]:995;
  23.     this.sock=new SocketReader(this,ar[0],port,port==995);
  24.     return false;
  25.   case ST_DATA+1: 
  26.     var user;
  27.     if(this.user.indexOf("|")!=-1)user=this.user.split("|")[0];
  28.     else user=this.user.split("@")[0];
  29.     this.send("USER "+user);
  30.     return false;
  31.   case ST_DATA+2:
  32.     this.send("PASS "+this.password);
  33.     return false;    
  34.   case ST_DATA+3:
  35.     this.send("STAT");
  36.     return false;        
  37.   case ST_DATA+4:
  38.     var fnd=aData.match(/\+OK\s(\d+)/);
  39.     if(fnd){
  40.       var cnt=this.main.wuGetVal(this.id,this.user,0);
  41.       cnt=cnt?parseInt(cnt):0;    
  42.       var num=parseInt(fnd[1]);
  43.       this.newData=num;      
  44.       if(num>=cnt){
  45.         this.mailCount=num-cnt;
  46.       }else{
  47.         this.main.wuSetVal(this.id,this.user,0,num);
  48.         this.mailCount=0;
  49.       }
  50.       this.mailData=this.getData(aData);
  51.       this.mailData.desc=this.getDesc();            
  52.     }
  53.     this.send("QUIT");
  54.     return false;            
  55.   case ST_DATA+5:
  56.     this.sock.close();
  57.     if(this.mailCount<0)this.reset();
  58.     else this.stage=ST_DATA;
  59.     this.main.setState(nsIWebMailNotifier.ST_MAILDATA,this.ind);    
  60.     return true;                
  61.   }  
  62.   this.onError();
  63.   return true;  
  64. }
  65. function stop(){
  66.   if(this.sock)this.sock.close();
  67. }
  68. function send(cmd){
  69.   this.sock.write(cmd+"\r\n");
  70. }
  71.  
  72. function calcCount(){
  73.   return this.mailCount;
  74. }
  75. function getMailURL(){
  76.   this.main.wuSetVal(this.id,this.user,0,this.newData);
  77.   delete this.newData;  
  78.   this.mailCount=0;
  79.   if(!this.main.newMailsOnly){
  80.     this.mailData.desc=this.getDesc();    
  81.     this.main.setState(nsIWebMailNotifier.ST_MAILDATA,this.ind);
  82.   }  
  83.   return null;
  84. }